package com.dianrui.firemenmonitor.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dianrui.firemenmonitor.R;
import com.dianrui.firemenmonitor.bean.Track;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TrackAdapter extends BaseAdapter {
    private List<Track> trackList;
    private Context context;

    public TrackAdapter(Context context, List<Track> trackList) {
        this.context = context;
        this.trackList = trackList;
    }

    public void refresh(List<Track> list) {
        this.trackList = list;
        this.notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return trackList.size();
    }

    @Override
    public Object getItem(int position) {
        return trackList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_track, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        if (trackList != null && trackList.size() > 0) {
            Track track=trackList.get(position);
            holder.time.setText(track.inputtime);
            holder.startPath.setText(track.address);
            holder.endPath.setText(track.address);
        }
        return convertView;
    }

     class ViewHolder {
        @BindView(R.id.time)
        TextView time;
        @BindView(R.id.start_path)
        TextView startPath;
        @BindView(R.id.end_path)
        TextView endPath;
        @BindView(R.id.click_track)
        LinearLayout click_track;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
